import { Controller, Get, Headers } from '@nestjs/common';
import { LogService } from './log.service';
import { JwtService } from '@nestjs/jwt';
import { Log } from './entities/log.entity';

@Controller('logs')
export class LogsController {
  constructor(
    private readonly logService: LogService,
    private readonly jwtService: JwtService,
  ) {}

  @Get()
  async getLogs(@Headers('authorization') authHeader: string): Promise<Log[]> {
    const token = authHeader.replace('Bearer ', '');
    const payload = this.jwtService.verify(token);
    const logs = await this.logService.findByUserId(payload.id);
    return logs;
  }
}
